package com.example.demo.service.imp;

import com.example.demo.controller.data.ReturnData;
import com.example.demo.dao.BannerDao;
import com.example.demo.entity.Banner;
import com.example.demo.service.BannerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class BannerServiceImp implements BannerService {
    @Resource
    BannerDao bannerDao;
    @Override
    public ReturnData getBanner() {
        return ReturnData.ok("获取成功",bannerDao.findAll());
    }

    @Override
    public ReturnData delete(int id) {
        Banner banner = bannerDao.findById(id).get();
        if (banner == null){
            return ReturnData.error("删除失败，没有对应的ID");
        }
        bannerDao.delete(banner);
        return ReturnData.ok("删除成功");
    }

    @Override
    public ReturnData add(Banner banner) {
        bannerDao.save(banner);
        return ReturnData.ok("添加成功");
    }

}
